package org.egedede.osgi.guishell.model.commands;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Properties;

import org.egedede.osgi.guishell.model.AbstractCommand;
import org.egedede.osgi.guishell.model.CommandType;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;

public class InstallBundleCommand extends AbstractCommand {

	public InstallBundleCommand() {
		super("Install", "Install a bundle", CommandType.FRAMEWORK);
	}

	public Object execute(Properties properties, PrintStream out, PrintStream error) {
		try {
			File file = (File)properties.get("bundle.file");
			String path = file.getCanonicalPath();
			path = "file:/"+path.replace("\\", "/");
			Bundle bundle = getContext().installBundle(path);
			return bundle.getBundleId();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace(error);
		} catch (BundleException e) {
			// TODO Auto-generated catch block
			e.printStackTrace(error);
		}
		return null;
	}

}
